'use strict';

module.exports = function countSameElements(collection) {
  let result=[];
  for(let i=0;i<collection.length;){
    let num=0;
    let summary=0;
    let object=new Object();
    for(let n=i;n<collection.length;n++){
      if(collection[n][0]==collection[i][0]){
        if(collection[n].length==1){
          num++;
          summary++;
        }
        else if(collection[n][1]=="["){
          let l=collection.length-1;
          summary=summary+parseInt(collection[n].substring(2,l));
          num++;  
        }    
        else{  
          let j=parseInt(collection[n].substring(2,3));        //截取数字字符并转成数字形式
          summary=summary+j;
          num++;       
        }
      }      
    }
    object.name=collection[i][0];
    object.summary=summary;
    result.push(object);
    i+=num;
  }
  return result;
}
